Having GDK_WINDOW_CHILD windows with root as the parent apparently works,
and metacity uses it. The current gdk_window_get_toplevel() returns the
root window for that, which is wrong, so we check that explicitly.
* @window: a #GdkWindow
*
* Gets the toplevel window that's an ancestor of @window.
+ *
+ * Any window type but %GDK_WINDOW_CHILD is considered a
+ * toplevel window, as is a %GDK_WINDOW_CHILD window that
+ * has a root window as parent.
*
* Return value: the toplevel window containing @window
**/
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
obj = (GdkWindowObject *)window;
+
while (GDK_WINDOW_TYPE (obj) == GDK_WINDOW_CHILD)
- obj = (GdkWindowObject *)obj->parent;
+ {
+ if (obj->parent == NULL ||
+ GDK_WINDOW_TYPE (obj->parent) == GDK_WINDOW_ROOT)
+ break;
+ obj = obj->parent;
+ }
return GDK_WINDOW (obj);
}